import Vue from 'vue'
import VueRouter from 'vue-router'
// import MyIndex from '../views/MyIndex.vue'
// import Mine from '../views/Mine.vue'
import login from '../views/login.vue'
import register from '../views/register.vue'
// import zhuye from '../views/zhuye.vue'
import index from '../views/index.vue'
import fabu from '../views/fabu.vue'
import help from '../views/help.vue'
import myhelp from '../views/myhelp.vue'
import needhelp from '../views/needhelp.vue'
import geren from '../views/geren.vue'
import manageUsers from '../views/manageUsers.vue'
import store from '@/store'



Vue.use(VueRouter)

const routes = [
  {
    path:'/',
    name:'login',
    component:login,
  },
  {
    path:'/register',
    name:'register',
    component:register
  },
  {
    path:'/index',
    name:'index',
    component:index,
    children:[
      {
        path:'/fabu',
        name:'fabu',
        component:fabu
      },
      {
        path:'/help',
        name:'help',
        component:help
      },
      {
        path:'/myhelp',
        name:'help',
        component:myhelp
      },
      {
        path:'/needhelp',
        name:'needhelp',
        component:needhelp
        
      },
      {
        path:'/geren',
        name:'geren',
        component:geren
      },
      {
      path:'/manageUsers',
      name:'manageUsers',
      component:manageUsers,
      beforeEnter: (to,from,next)=>{
        let roleid = store.state.account.user.role.id;
        console.log(871231)
        console.log(roleid)
        if(roleid==3){
          next()
        }else{
          next({path:'/404',replace:true})
        }
      }
    }
    ]
  },
  {
    path: '/404',
    name: 'NotFound',
    component:() => import('@/views/NotFound')
  },
  {
    path:'/403',
    name:'NotAuth',
    component:()=>import('@/views/NotAuth')
  },{
  path:'*',
  redirect:'/404'
}
]

const router = new VueRouter({
  routes
})

export default router

